package com.hxkj.controller;

import com.hxkj.domain.po.Column;
import com.hxkj.domain.po.Navigation;
import com.hxkj.domain.po.NavigationTree;
import com.hxkj.service.NavigationService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

/**
 * 首页导航栏控制器
 * <p>
 * Created by chenfangzhou on 2018/6/6.
 */
@RestController
@RequestMapping("/navigation")
public class NavigationController {

    private static final Logger LOGGER = LoggerFactory.getLogger(NavigationController.class);

    @Autowired
    private NavigationService navigationService;


    /**
     * 获取首页导航栏列表
     *
     * @param navigation
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public Callable<ResultDataStruct<List<NavigationTree>>> getNavigationList(@RequestBody Navigation navigation) throws Exception {
        return () -> navigationService.getNavigationList(navigation == null ? new Navigation() : navigation);

    }

    /**
     * 获取单个导航栏
     *
     * @param navigation
     * @return Navigation
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Navigation>> getNavigation(@RequestBody Navigation navigation) throws Exception {
        return () -> navigationService.getNavigation(navigation);
    }

    /**
     * 新增导航栏
     *
     * @param navigation
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultDataStruct saveNavigation(@RequestBody Navigation navigation) throws Exception {
        return navigationService.saveNavigation(navigation);
    }

    /**
     * 删除导航栏
     *
     * @param navigation
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct deleteNavigation(@RequestBody Navigation navigation) throws Exception {
        return navigationService.deleteNavigation(navigation);
    }

    /**
     * 更新导航栏
     *
     * @param navigation
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct updateNavigation(@RequestBody Navigation navigation) throws Exception {
        return navigationService.updateNavigation(navigation);
    }

    /**
     * 更新排序
     *
     * @param map 导航栏信息
     * @throws Exception
     */
    @RequestMapping(value = "/modifyOrderId", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> modifyOrderId(@RequestBody Map<String, Object> map) throws Exception {
        return () -> navigationService.modifyOrderId(map);
    }

    /**
     * 获取首页导航栏列表 不带树形结构
     *
     * @param navigation
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getnavigations", method = RequestMethod.POST)
    public Callable<ResultDataStruct<List<Navigation>>> getList(@RequestBody Navigation navigation) throws Exception {
        return () -> navigationService.getList(navigation == null ? new Navigation() : navigation);

    }

    /**
     * 根据主键删除导航栏,不判断是否有子级
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/deleteByPrimarykey", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct deleteByPrimarykey(@RequestBody Long navigationId) throws Exception {
        return navigationService.deleteByPrimarykey(navigationId);
    }


    /**
     * @return com.platform.common.domain.result.ResultMessageStruct
     * @author Mr.zheng
     * @Description saveColumnToNavigation 将分类添加到导航栏
     * @Date 15:58 2018/7/26
     * @Param [navigationId]
     **/
    @RequestMapping(value = "/saveColumnToNavigation", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> saveColumnToNavigation(@RequestBody Column column) throws Exception {
        return () -> navigationService.saveColumnToNavigation(column);
    }
}
